package com.example.fluentmybatis.service.impl;

import cn.org.atool.generator.FileGenerator;
import cn.org.atool.generator.database.DbType;
import com.example.fluentmybatis.entity.CodeGeneratorEntry;
import com.example.fluentmybatis.service.ICodeGeneratorService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : Mr Li
 * @description : 代码生成实现类
 * @since : 2021/8/4 10:28 上午
 */
@Service
public class CodeGeneratorServiceImpl implements ICodeGeneratorService {

    @Override
    public void codeGenerator(CodeGeneratorEntry entry) {
        List<String> tableNameList = entry.getTableNameList();
        FileGenerator.build(true, false)
                .globalConfig(g -> g
                        .setOutputDir(entry.getSrcDir())
                        .setBasePackage(entry.getBasePackage())
                        .setDaoPackage(entry.getDaoDir())
                        .setDataSource(DbType.MYSQL,entry.getDriver(),entry.getUrl(), entry.getUserName(), entry.getPassWord())
                )
                .tables(t->tableNameList.forEach(t::table))
                .execute();
    }
}
